package com.nondo.dean.order.model.param;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.nondo.dean.order.model.ConsigneeBean;

@JsonIgnoreProperties(ignoreUnknown = true)
public class AppOrderParam {
    /**
     * 收货人信息
     */
    private ConsigneeBean consignee;

    /**
     * 购物车信息
     */
    private List<CartParam> cartList;

    /**
     * 支付方式
     */
    private Integer payment;

    /**
     * @return the consigneeBean
     */
    public ConsigneeBean getConsignee() {
        return consignee;
    }

    /**
     * @param consigneeBean the consigneeBean to set 收货人信息
     */
    public void setConsignee(ConsigneeBean consignee) {
        this.consignee = consignee;
    }

    /**
     * @return the payment
     */
    public Integer getPayment() {
        return payment;
    }

    /**
     * @param payment the payment to set 支付方式
     */
    public void setPayment(Integer payment) {
        this.payment = payment;
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class CartParam {
        /**
         * 购物车主键ID
         */
        private Integer id;

        /**
         * 产品ID
         */
        private Integer productId;

        /**
         * 产品数量
         */
        private Integer num;
        
        /**
         * 定制内容
         */
        private String note;

        /**
         * @return the id
         */
        public Integer getId() {
            return id;
        }

        /**
         * @param id the id to set
         */
        public void setId(Integer id) {
            this.id = id;
        }

        /**
         * @return the productId
         */
        public Integer getProductId() {
            return productId;
        }

        /**
         * @param productId the productId to set
         */
        public void setProductId(Integer productId) {
            this.productId = productId;
        }

        /**
         * @return the num
         */
        public Integer getNum() {
            return num;
        }

        /**
         * @param num the num to set
         */
        public void setNum(Integer num) {
            this.num = num;
        }

        /**
         * @return the note
         */
        public String getNote() {
            return note;
        }

        /**
         * @param note the note to set
         */
        public void setNote(String note) {
            this.note = note;
        }

    }

    /**
     * @return the cartList
     */
    public List<CartParam> getCartList() {
        return cartList;
    }

    /**
     * @param cartList the cartList to set 购物车信息
     */
    public void setCartList(List<CartParam> cartList) {
        this.cartList = cartList;
    }

    /**
     * 客户端输入参数校验
     * 
     * @param param {@link AppOrderParam}
     * @return 字符串 错误提示
     */
    public static String checkInputParam(AppOrderParam orderParam) {
        String message = null;
        Integer payment = orderParam.getPayment();
        ConsigneeBean consigneeBean = orderParam.getConsignee();
        List<CartParam> cartList = orderParam.getCartList();
        if (payment == null) {
            message = "支付方式缺失";
            return message;
        }
        if (consigneeBean == null || cartList == null) {
            message = "收货地址或者订单明细缺失";
            return message;
        }
        if (consigneeBean != null) {
            if (StringUtils.isBlank(consigneeBean.getUserName())) {
                message = "收货人姓名不能为空";
                return message;
            }
            if (StringUtils.isBlank(consigneeBean.getUserTelphone())) {
                message = "收货人电话不能为空";
                return message;
            }
            if (StringUtils.isBlank(consigneeBean.getUserAddress())) {
                message = "收货人地址不能为空";
                return message;
            }
        }
        return message;
    }

}
